/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package xcore.constraint.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import xcore.constraint.ConstraintPackage;
import xcore.constraint.XIntCstExpr;
import xcore.constraint.XIntVarExpr;
import xcore.constraint.XScalar;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>XScalar</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link xcore.constraint.impl.XScalarImpl#getParameters <em>Parameters</em>}</li>
 *   <li>{@link xcore.constraint.impl.XScalarImpl#getXScalar <em>XScalar</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class XScalarImpl extends XIntVarExprImpl implements XScalar {
	/**
	 * The cached value of the '{@link #getParameters() <em>Parameters</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameters()
	 * @generated
	 * @ordered
	 */
	protected EList<XIntVarExpr> parameters;

	/**
	 * The cached value of the '{@link #getXScalar() <em>XScalar</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getXScalar()
	 * @generated
	 * @ordered
	 */
	protected XIntCstExpr xScalar;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XScalarImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ConstraintPackage.Literals.XSCALAR;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<XIntVarExpr> getParameters() {
		if (parameters == null) {
			parameters = new EObjectContainmentEList<XIntVarExpr>(XIntVarExpr.class, this, ConstraintPackage.XSCALAR__PARAMETERS);
		}
		return parameters;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public XIntCstExpr getXScalar() {
		return xScalar;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetXScalar(XIntCstExpr newXScalar, NotificationChain msgs) {
		XIntCstExpr oldXScalar = xScalar;
		xScalar = newXScalar;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ConstraintPackage.XSCALAR__XSCALAR, oldXScalar, newXScalar);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setXScalar(XIntCstExpr newXScalar) {
		if (newXScalar != xScalar) {
			NotificationChain msgs = null;
			if (xScalar != null)
				msgs = ((InternalEObject)xScalar).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ConstraintPackage.XSCALAR__XSCALAR, null, msgs);
			if (newXScalar != null)
				msgs = ((InternalEObject)newXScalar).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ConstraintPackage.XSCALAR__XSCALAR, null, msgs);
			msgs = basicSetXScalar(newXScalar, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ConstraintPackage.XSCALAR__XSCALAR, newXScalar, newXScalar));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ConstraintPackage.XSCALAR__PARAMETERS:
				return ((InternalEList<?>)getParameters()).basicRemove(otherEnd, msgs);
			case ConstraintPackage.XSCALAR__XSCALAR:
				return basicSetXScalar(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ConstraintPackage.XSCALAR__PARAMETERS:
				return getParameters();
			case ConstraintPackage.XSCALAR__XSCALAR:
				return getXScalar();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ConstraintPackage.XSCALAR__PARAMETERS:
				getParameters().clear();
				getParameters().addAll((Collection<? extends XIntVarExpr>)newValue);
				return;
			case ConstraintPackage.XSCALAR__XSCALAR:
				setXScalar((XIntCstExpr)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ConstraintPackage.XSCALAR__PARAMETERS:
				getParameters().clear();
				return;
			case ConstraintPackage.XSCALAR__XSCALAR:
				setXScalar((XIntCstExpr)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ConstraintPackage.XSCALAR__PARAMETERS:
				return parameters != null && !parameters.isEmpty();
			case ConstraintPackage.XSCALAR__XSCALAR:
				return xScalar != null;
		}
		return super.eIsSet(featureID);
	}

} //XScalarImpl
